package com.example.rrr_map;

import java.util.ArrayList;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;


import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class LVWarriorsAdapter extends BaseAdapter {
	private static ArrayList<User> persons;
	private User obj;
	private LayoutInflater mInflater;
	
	public LVWarriorsAdapter(Context context, ArrayList<User> rel) {
		persons = rel;
		mInflater = LayoutInflater.from(context);
	}
	
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return persons.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return persons.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@TargetApi(Build.VERSION_CODES.GINGERBREAD)
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if(convertView == null) {
			convertView = mInflater.inflate(R.layout.lv_layout_warrior, null);
            holder = new ViewHolder();
            holder.warriorName = (TextView) convertView.findViewById(R.id.warriorname);
			holder.warriorLevel = (TextView) convertView.findViewById(R.id.warriorlevel);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		
		
		holder.warriorName.setText("Name: " + persons.get(position).getName());
		holder.warriorLevel.setText("Level: " + persons.get(position).getLevel());
		
		
		
		// TODO Auto-generated method stub
		return convertView;
	}

	static class ViewHolder {
		TextView warriorName;
		TextView warriorLevel;
	}
	
	
	
}
